package com.koron.order.experiment.bean.dto;

import lombok.Data;

/**
 * @ClassName KeyName
 * @description
 * @Author zhouj
 * @Date 2021/10/15 14:54
 */
@Data
public class KeyName {

    private volatile String prefix;

    private volatile String suffix;

    private volatile Integer sort;

    public String getCurr() {
        return prefix + suffix + sort;
    }

    public synchronized String getNext() {
        return prefix + suffix + (sort + 1);
    }

    public synchronized void init() {
        this.prefix = "var";
        this.suffix = "1.";
        this.sort = 1;
    }

    public synchronized int setNextSort() {
        this.sort += 1;
        return this.sort;
    }

    public synchronized int setNextSuffix() {
        String s = this.suffix.substring(0, this.suffix.length() - 1);
        int i = Integer.parseInt(s);
        this.suffix = (i + 1) + ".";
        this.sort = 0;
        return this.sort;
    }

}
